package twentytwentyone_3;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: Zahi
 * @Description:
 * @Date Created in 2021-03-24 13:52
 * @Modified By:
 */
public class CountBinarySubstrings_696 {
    public static void main(String[] args){

    }

    public static int countBinarySubstrings(String s){
        List<Integer> counts = new ArrayList<Integer>();
        int ptr = 0, n = s.length();
        while (ptr < n) {
            char c = s.charAt(ptr);
            int count = 0;
            while (ptr < n && s.charAt(ptr) == c) {
                ++ptr;
                ++count;
            }
            counts.add(count);
        }

        int result = 0;
        for (int i = 0; i < counts.size() - 1; i++) {
            result += Math.min(counts.get(i),counts.get(i + 1));
        }
        return result;
    }
}
